# -*- coding: utf-8 -*-
# @Time    : 2022/2/18 15:29
# @Author  : Cph
# @File    : add_.py
# @remarks :重置密码
import time

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver

# 个人资料路径
user_data_dir = (r'--user-data-dir=C:\Users\陈品华\AppData\Local\Google\Chrome\User Data')
# 加载配置数据
option = webdriver.ChromeOptions()
option.add_argument(user_data_dir)

_list = ['hzsdsjj_001',
'hzsdsjj_002',
'hzsdsjj_003',
'hzsdsjj_004',
'hzsdsjj_005',
'hzsdsjj_006',
'hzsdsjj_007',
'hzsdsjj_008',
'hzsdsjj_009',
'hzsdsjj_010',
'hzsdsjj_011',
'hzsdsjj_012',
'hzsdsjj_013',
'hzsdsjj_014',
'hzsdsjj_015',
'hzsdsjj_016',
'hzsdsjj_017',
'hzsdsjj_018',
'hzsdsjj_019',
'hzsdsjj_020',
'hzsdsjj_021',
'hzsdsjj_022',
'hzsdsjj_023',
'hzsdsjj_024',
'hzsdsjj_025',
'hzsdsjj_026']
driver = webdriver.Chrome()
driver.maximize_window()
# 网址/地址
url = 'https://10.10.142.221:8015/ucbb/static/login'
# 启动网页
driver.get(url)
# 安全警告 高级-继续
# driver.find_element_by_xpath('//*[@id="details-button"]').click()
# driver.find_element_by_xpath('//*[@id="proceed-link"]').click()
time.sleep(1)
username = driver.find_element_by_xpath('//*[@id="username"]')
username.send_keys('dsc')
password = driver.find_element_by_xpath('//*[@id="password"]')
password.send_keys('DSC_test@0209')
time.sleep(0.3)
driver.find_element_by_xpath('//*[@id="root"]/div/div/div[6]/div/div/div/form/button').click()
time.sleep(1)
# 用户管理
driver.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[1]/div/div/ul/div[1]/div[1]').click()
time.sleep(0.8)
# 系统用户管理
driver.find_element_by_xpath('/html/body/div/div/div/div[2]/div[1]/div/div/ul/div[1]/ul/li[1]/a').click()
time.sleep(1)
# driver.switch_to.frame('dt-layout-content')
for a in _list:
    print(a)
    time.sleep(0.5)
    # 输入框
    # /html/body/div/div/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/form/div/div[2]/div/span/input
    driver.find_element_by_xpath('/html/body/div/div/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/form/div/div[2]/div/span/input').clear()
    driver.find_element_by_xpath('/html/body/div/div/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/form/div/div[2]/div/span/input').send_keys(a)
    time.sleep(0.5)
    # 搜索
    driver.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[2]/div[2]/div/div/div/div/div[1]/div/button[1]').click()
    time.sleep(0.5)
    # 重置密码
    driver.find_element_by_xpath('//*[@id="root"]/div/div/div[2]/div[2]/div[2]/div/div/div/div/div[2]/div/div/div[1]/div/div/table/tbody/tr/td[7]/a[3]').click()
    # 确认
    time.sleep(1)
    try:
        driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div[2]/div[3]/button[2]').click()
        time.sleep(0.5)
    except NoSuchElementException:
        driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div[2]/div[3]/button[2]').click()
        time.sleep(0.5)
    time.sleep(0.5)
driver.close()
